/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#include <cubefs/api/api.hpp>

#include <decls.hpp>
#include <notifier.hpp>
#include <stream.hpp>
#include <logs.hpp>





using namespace cubefs::api;


JNIEXPORT void JNICALL METADATA1(TypeSystem, InitTypeSystem) (JNIEnv *env, jclass)
{
    CUBEFS_EXC_BEGIN

    InitTypeSystem();

    

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL METADATA1(TypeSystem, DestroyTypeSystem) (JNIEnv *env, jclass)
{
    CUBEFS_EXC_BEGIN

    DestroyTypeSystem();

    CUBEFS_EXC_HANDLE
}

JNIEXPORT jlong JNICALL METADATA1(TypeSystem, FindType) (JNIEnv *env, jclass, jstring name)
{
    CUBEFS_EXC_BEGIN

    const char *str = env->GetStringUTFChars(name, NULL);
    if (str == NULL) {
        return 0; /* OutOfMemoryError already thrown */
    }

    jlong h0 = Ptr2Handle(TypeSystem::instance()->Find(String(str)));

    env->ReleaseStringUTFChars(name, str);

    return h0;

    CUBEFS_EXC_HANDLE
    return 0;
}


JNIEXPORT jlong JNICALL METADATA1(TypeSystem, ListTypes) (JNIEnv *env, jclass)
{
    CUBEFS_EXC_BEGIN

    ListOfTypes* lst = TypeSystem::instance()->Types();
    
    return Ptr2Handle(lst);
    
    CUBEFS_EXC_HANDLE
    return 0;
}


JNIEXPORT void JNICALL METADATA1(TypeSystem, InitStreams) (JNIEnv *env, jclass, jclass iStream, jclass oStream)
{
    CUBEFS_EXC_BEGIN

    InitStreams(env, iStream, oStream);

    CUBEFS_EXC_HANDLE
}

JNIEXPORT void JNICALL METADATA1(TypeSystem, InitLogHandler) (JNIEnv *env, jclass, jclass clazz)
{
    CUBEFS_EXC_BEGIN

    InitLogHandler(env, clazz);

    CUBEFS_EXC_HANDLE
}


JNIEXPORT void JNICALL METADATA1(TypeSystem, CleanStreams) (JNIEnv *env, jclass)
{
    CUBEFS_EXC_BEGIN

    CleanStreams(env);

    CUBEFS_EXC_HANDLE
}